import 'package:flutter/material.dart';
import 'package:flutter_qr_reader/qrcode_reader_view.dart';
import 'package:fsharing/ui/widgets/background_container.dart';
import 'package:fsharing/ui/widgets/round_back_button.dart';

class QrcodePage extends StatefulWidget {
  @override
  _QrcodePageState createState() => _QrcodePageState();
}

class _QrcodePageState extends State<QrcodePage> {
  GlobalKey<QrcodeReaderViewState> _key = GlobalKey();

  @override
  Widget build(BuildContext context) {
    return BackgroundContainer(
      child: Scaffold(
        appBar: AppBar(
          leading: RoundBackButton(),
        ),
        body: QrcodeReaderView(
          key: _key,
          onScan: _onScan,
        ),
      ),
    );
  }

  Future _onScan(String data) async {
    debugPrint('_onScan data = $data');
    if (data != null) {
      Navigator.of(context).pop(data);
    }
  }
}
